<%--
  Created by IntelliJ IDEA.
  User: 15516
  Date: 2020/12/14
  Time: 20:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>这是一个测试jsp</title>
    <script src="js/jquery.min.js"></script>
    <script src="js/echarts.min.js"></script>
</head>
<body>
<!-- 为ECharts准备一个具备大小（宽高）的Dom -->
<div id="main1" style="width: 600px;height:600px; position: relative;margin: 0 auto" ></div>

<script type="text/javascript">
    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('main1'));

    // 指定图表的配置项和数据
    option = {
        title: {
            text: "2011年不同月份的租车情况",
        },
        toolbox: {
            show: true,
            feature: {
                mark: {show: true},
                dataView: {show: true, readOnly: false},
                magicType: {show: true, type: ['line', 'bar']},
                restore: {show: true},
                saveAsImage: {show: true}
            }
        },
        angleAxis: {
            type: 'category',
            data: []
        },
        radiusAxis: {},
        polar: {},
        series: [{
            type: 'bar',
            data: [],
            coordinateSystem: 'polar',
            name: 'count',
            stack: 'a'
        }],
        legend: {
            show: true,
            data: ['count']
        }
    };


    var year = [];
    var count = [];

    $.ajax({
        url: 'ys',
        method: "get",
        dataType: "json",
        success: function (data) {
            alert(JSON.stringify(data));
            if (data) {
                for (var i = 0; i <12; i++) {
                    year.push(data[i]['year']);
                }
                for (var i = 0; i < data.length; i++) {
                    count.push(data[i]['count']);
                }
                myChart.setOption({
                    angleAxis: {
                        data: year
                    },
                    series: [{
                        data: count
                    }]
                })
            }

        },
        error: function (errMsg) {
            console.error(errMsg)
        }

    });

    myChart.setOption(option);


    // 使用刚指定的配置项和数据显示图表。

</script>
</body>
</html>
